﻿@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";

}
<style>
    .patListTB {
        width: 100%;
        border: 1px #eee solid;
        margin-bottom: 10px;
    }

        .patListTB tr td {
            text-align: center;
            border: 1px #eee solid;
            line-height: 30px;
            height: 30px;
            padding-left: 40px;
        }

        .patListTB tr th {
            text-align: center;
            background-color: #eee;
            border: 1px #eee solid;
            line-height: 30px;
        }
</style>
<form id="form1">
    <div style="padding-top:18px; margin-right: 30px;">
        <table class="form">
            <tr>
                <th class="formTitle" colspan="4">患者信息：</th>
                <td class="formValue" style="white-space: nowrap;text-overflow: ellipsis;text-align:center;font-style:italic;">
                    <input id="brjs" name="brjs" type="text" class="form-control required" value="病人简述" readonly="readonly" style="border:none" />
                    <input id="zyh" name="zyh" type="hidden" class="form-control required" value="住院号" readonly="readonly" style="border:none;" />
                    <input id="mzh" name="mzh" type="hidden" class="form-control required" value="门诊号" readonly="readonly" style="border:none;" />
                </td>
            </tr>
        </table>
        <table class="form">
            <tr>
                <th class="formTitle">病历类型：</th>
                <td class="formValue">
                    <select id="bllx" class="form-control required" data-EnumType="EnumBllx">
                        <option value="">==请选择==</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th class="formTitle">病历时间：</th>
                <td class="formValue">
                    <input id="blsj" type="text" class="form-control input-wdatepicker formClearIgnore" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss'})" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">模板权限：</th>
                <td class="formValue">
                    <select id="mbqx" name="mbqx" class="form-control required" data-EnumType="Enummbqx"></select>
                </td>
            </tr>

        </table>
        <div id="dv_mblb" style="margin-left: 25px;">
            <table id="mbgridList"></table>
        </div>

    </div>
</form>

<script>
    var keyValue = $.request("keyValue");
    var bllx = $.request("bllx");
    var zyh = $.request("zyh");
    var mzh = $.request("mzh");

    $(function () {
        if (!!zyh) {
            $.najax({
                url: "/MedicalRecordManage/PatInfo/MedRecordTreeEditJson",
                data: { keyValue: keyValue, bllx: bllx,zyh:zyh },
                dataType: "json",
                success: function (data) {
                    $("#form1").formSerialize(data);
                }
            });
        }
        else if (!!mzh) {
            $.najax({
                url: "/MedicalRecordManage/Outpatient/MedRecordTreeEditJson",
                data: { keyValue: keyValue, bllx: bllx, mzh: mzh },
                dataType: "json",
                success: function (data) {
                    $("#form1").formSerialize(data);
                }
            });
        }
        else {
            $('#zt').click(function () {
                return false;
            });
        }
        initControl();
    });

    function initControl() {
        var mzbz = '@((int)EnumMzbz.zy)';
        if (!!mzh) {
            mzbz = '@((int)EnumMzbz.mz)';
        }
        $("#bllx").bindSelect({
            url: "/SystemManage/Common/GetBllxList?mzbz=" + mzbz,
            id: "Code",
            text: "Name"
        });
        $('#bllx').val(bllx);
        mbgridList();
    }

    function AcceptClick(callBack) {
        if (!$('#form1').formValid()) {
            return false;
        }

        var mbRowId = $("#mbgridList").jqGrid('getGridParam', 'selrow');
        var mbData=$("#mbgridList").jqGrid('getRowData', mbRowId);
        if (mbRowId != null) {
            if ('@ViewBag.IsEnableEditor'=="true" && $("#bllx").val() == '@((int)EnumBllx.basy)') {
                top.top.$.Newtouchtab.addTabWithOutMenu({ name: "病案首页", enName: "", url: "/MRHomePage/MRHomePage/Main?mbbh=" + mbRowId + "&keyValue=&zyh=" + $("#zyh").val(), AppId: "EMR" });
            }
            else {
                top.top.$.Newtouchtab.addTabWithOutMenu({ name: "病历操作", enName: "", url: "/MedicalRecordManage/MedicalRecord/MedicalRecordEdiForAdd?mbbh=" + mbRowId + "&zyh=" + $("#zyh").val(), AppId: "EMR" });
            }
            $.modalClose();
        }
        else {
            $.modalAlert("请选择病历模板", 'warning');
        }
    }



    $('#bllx').change(function () {
        mbListRefresh()
    });

    $('#mbqx').change(function () {
        mbListRefresh()
    });

    function mbListRefresh()
    {
        if ($("#mbqx").val() != "" && $("#mbqx").val() != null && $("#mbqx").val() != "undefined")
        {
            $("#mbgridList").jqGrid('setGridParam', {
                postData: { mbqx: $("#mbqx").val(), bllx: $("#bllx").val() },
            }).trigger('reloadGrid');
        }
    }

    function mbgridList() {
        //debugger
        var $gridList = $("#mbgridList");
        $gridList.dataGrid({
            treeGrid: true,
            treeGridModel: "adjacency",
            ExpandColumn: "CreateTime",
            url: "/MedicalRecordManage/PatInfo/GetMedRecordTempList",
            postData: { mbqx: $("#mbqx").val(), bllx: $("#bllx").val() },
            height: $(window).height() - 180,
            colModel: [
                { label: "模板ID", name: "Id", hidden: true, key: true },
                { label: "模板加载方式", name: "LoadWay", hidden: true },
                { label: "模板路径", name: "mblj", hidden: true },
                {
                    label: '模板类型', name: 'bllxmc', hidden: true, width: 60, align: 'center'
                },
                {
                    label: '模板名称', name: 'mbmc', width: 230, align: 'left'
                },
                {
                    label: "来源", name: "Memo", width: 30, align: 'left', formatter: function (val) {
                        if (val != "" && val != null) {
                            return "[转]";
                        }
                        else {
                            return "";
                        }
                    }
                },
                {
                    label: "模板性质", name: "Isempty", width: 100, align: "center", formatter: function (cellvalue) {
                        if (cellvalue == "1")
                            return "空模板";
                        else
                            return '定制模板';
                    }
                },
                { label: '创建日期', name: 'CreateTime', width: 130, align: 'center', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },
                { label: '修改日期', name: 'LastModifierTime', width: 130, align: 'center', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },

            ], ondblClickRow: function (row) {
                //debugger
                var mbRowId = $("#mbgridList").jqGrid('getGridParam', 'selrow');
                var mbData = $("#mbgridList").jqGrid('getRowData', mbRowId);
                if (mbRowId != null) {
                    if ('@ViewBag.IsEnableEditor' == "true" && $("#bllx").val() == '@((int)EnumBllx.basy)') {
                        top.top.$.Newtouchtab.addTabWithOutMenu({ name: "病案首页", enName: "", url: "/MRHomePage/MRHomePage/Main?mbbh=" + mbRowId + "&keyValue=&zyh=" + $("#zyh").val(), AppId: "EMR" });
                    }
                    else if (mbData.LoadWay == '@((int)EnummbqxTempLoadWay.View)' && !!mbData.mblj)
                    {
                        top.top.$.Newtouchtab.addTabWithOutMenu({ name: mbData.mbmc, enName: "", url: mbData.mblj+"?mbbh=" + mbRowId + "&keyValue=&zyh=" + $("#zyh").val(), AppId: "EMR" });
                    }
                    else {
                        top.top.$.Newtouchtab.addTabWithOutMenu({ name: "病历操作", enName: "", url: "/MedicalRecordManage/MedicalRecord/MedicalRecordEdiForAdd?mbbh=" + mbRowId + "&zyh=" + $("#zyh").val(), AppId: "EMR" });
                    }
                    $.modalClose();
                }
                else {
                    $.modalAlert("请选择病历模板", 'warning');
                }
        }
        });
        //$("#btn_search").click(function () {
        //    $gridList.jqGrid('setGridParam', {
        //        postData: { keyword: $("#txt_keyword").val() },
        //    }).trigger('reloadGrid');
        //});
    }


</script>